#modeltag({tagcode:"jxbrms_systemstaffinfo",id:params[0],name:"systemStaffInfo"})
#include("/common/layout/bootstrap_form_layout.html")
#@layout()
#define head()

#jx_css({file:"content.css,check_tip.css"})
#define title()
#(jxrb.message(actionName,"systemStaffInfo"))
#end
<script type="text/javascript" src="#(jxwebpath.js)WdatePicker/WdatePicker.js" ></script>
<script language="javascript">
  seajs.use(["jquery", "jx_msgbox", "#(jxwebpath.js)staff", "jac"], function ($, msgbox, staff)
  {
    $("#b_submit").on("click", function ()
    {
      if (checkStaffInfo())
      {
        msgbox.confirm({url: "#(controllerKey)#(action)/"},
        function ()
        {
          msgbox.close();
          window.parent.refreshTree($("#parentId").val());
          returnInfo();
        }, function ()
        {
          returnInfo();
        });
      }
    });

    var action = '#(action)';
    $("#b_return").on("click", function () {
      if (action == 'added') {
        location.href = "#(backurl)";
      } else {
        returnInfo()
      }
    });

    function returnInfo()
    {
      var parentId = $("#parentId").val();
      if (parentId == "") {
        location.href = "#(controllerKey)1-1"
      } else {
        location.href = "#(controllerKey)2-" + parentId;
      }
    }

    function checkStaffInfo()   /*校验*/
    {
      var staffName = $("#staffName").val();
      var viewNum = $("#viewNum").val();
      if ($.trim(staffName) == "" | $.trim(staffName == null))
      {
        alert('#(jxrb.message("systemStaffInfo.staffName.isNull"))');
        return false;
      }
      if (isNaN($.trim(viewNum)))
      {
        alert('#(jxrb.message("systemStaffInfo.viewNum.isNum"))');
        return false;
      }
      if ( action == 'added') {
        var organize = $("#organize").val();
        if ($.trim(organize) == "" | $.trim(organize) == null)
        {
          alert('#(jxrb.message("orgaize.isNotNull"))');
          return false;
        }
      }
      return true;
    }
    ;

    window.deleteData = staff.deleteData;
    window.deletePhone = staff.deletePhone;
    window.deleteEmail = staff.deleteEmail;
    window.deleteIM = staff.deleteIM;
    window.addPhones = staff.addPhones;
    window.addEmails = staff.addEmails;
    window.addIMs = staff.addIMs;
    window.addDatas = staff.addDatas;

    if ('#(action)' == 'added') {
      var divPostIndex = 100;
      var postIds = "";
    }
    function collect() { /*遍历*/
      var action = '#(action)';
      if (action == 'edited')
      {
        $("input").each(
                function () {
                  if (($(this).attr("id") != undefined) && ($(this).attr("id").search("postId") != -1)) {
                    postIds += $(this).val() + ";";
                  }
                }
        );
      }
    }

    function checkRepeat(info, infos) /*查重*/
    {
      var strArray = new Array();
      strArray = infos.split(";");
      for (var i = 0; i < strArray.length; i++)
      {
        if (info == strArray[i])
        {
          alert('#(jxrb.message("duty.chongfu"))');
          return false;
        }
      }
      return true;
    }

    function addPost() /*添加职位*/
    {
      collect();
      var postInfo = $("#postInfo").val();
      var postId = $("#postId").val();
      console.log("postInfo=" + postInfo);
      console.log("postId=" + postId);
      if (postIds == "") {
        postIds += "";
      }
      console.log("postIds=" + postIds)
      if (checkRepeat(postId, postIds)) {
        $("#addPost").append('<div id="divPost_' + divPostIndex + '"><input type="text" name="postName" value="' + postInfo + '" size="30" id="postInfo" disabled="disabled"/><input type="hidden" name="postId" value="' + postId + '" id="postId" />&nbsp;<input type="button" class="remove" value="删除" /></div>').find("input.remove").click(function () {
          $(this).parent().remove();
        });
      }
      postIds += postId + ";";
      divPostIndex++;
    }

    function deletePost(o) { /*删除*/
      document.getElementById("addPost").removeChild(document.getElementById("divPost_" + o));
    }


    window.addPost = addPost;
    window.deletePost = deletePost;
  });

  seajs.use(['jx_pinyin'], function (jxpy) {
    jxpy({nameObject: "#staffName", codeObject: "#spellSimple", qpCodeObject: "#spellFull"});
  });
</script>
#end

#define bodyExt()
class="gray-bg"
#end

#define form()
#include("info.html")
<div id="dataInfo">

</div>
#end

#define formAfter()
<center>
  #jx_button({value:"action.save",class:"btn btn-primary"})&nbsp;&nbsp;&nbsp;&nbsp;
  #jx_button({value:"action.return",id:"b_return",class:"btn btn-danger"})
</center>
#end

